 1.电商分析之--会员活跃度之Datax 数据导出
   
   基本概念及安装参见《附录一 DataX快速入门》
   ADS有4张表需要从数据仓库的ADS层导入MySQL，即：Hive => MySQL
   ads.ads_member_active_count
   ads.ads_member_retention_count
   ads.ads_member_retention_rate
   ads.ads_new_member_cnt
   
   -- MySQL 建表
   -- 活跃会员数
   create database dwads;
   drop table if exists dwads.ads_member_active_count;
   create table dwads.ads_member_active_count(
`dt` varchar(10) COMMENT '统计日期',
`day_count` int COMMENT '当日会员数量',
`week_count` int COMMENT '当周会员数量',
`month_count` int COMMENT '当月会员数量',
primary key (dt)
);
   
   -- 新增会员数
   drop table if exists dwads.ads_new_member_cnt;
   create table dwads.ads_new_member_cnt
(
`dt` varchar(10) COMMENT '统计日期',
`cnt` int,
primary key (dt)
);

   -- 会员留存数
   drop table if exists dwads.ads_member_retention_count;
   create table dwads.ads_member_retention_count
(
`dt` varchar(10) COMMENT '统计日期',
`add_date` varchar(10) comment '新增日期',
`retention_day` int comment '截止当前日期留存天数',
`retention_count` bigint comment '留存数',
primary key (dt)
) COMMENT '会员留存情况';
    
   -- 会员留存率
   drop table if exists dwads.ads_member_retention_rate;
   create table dwads.ads_member_retention_rate
(
`dt` varchar(10) COMMENT '统计日期',
`add_date` varchar(10) comment '新增日期',
`retention_day` int comment '截止当前日期留存天数',
`retention_count` bigint comment '留存数',
`new_mid_count` bigint comment '当日会员新增数',
`retention_ratio` decimal(10,2) comment '留存率',
primary key (dt)
) COMMENT '会员留存率';
   
   导出活跃会员数(ads_member_active_count)
   export_member_active_count.json
   hdfsreader => mysqlwriter
hdfs://linux121:9000/user/hive/warehouse/ads.db/ads_member_active_count

{
	"job": {
		"setting": {
			"speed": {
				"channel": 1
			}
		},
		"content": [{
			"reader": {
				"name": "hdfsreader",
				"parameter": {
					"path": "/user/hive/warehouse/ads.db/ads_member_active_count/dt=$do_date/*",
					"defaultFS": "hdfs://linux121:9000",
					"column": [{
							"type": "string",
							"value": "$do_date"
						}, {
							"index": 0,
							"type": "string"
						},
						{
							"index": 1,
							"type": "string"
						},
						{
							"index": 2,
							"type": "string"
						}
					],
					"fileType": "text",
					"encoding": "UTF-8",
					"fieldDelimiter": ","
				}
			},
			"writer": {
				"name": "mysqlwriter",
				"parameter": {
					"writeMode": "replace",
					"username": "hive",
					"password": "12345678",
					"column": ["dt", "day_count", "week_count", "month_count"],
					"preSql": [
						""
					],
					"connection": [{
						"jdbcUrl": "jdbc:mysql://linux123:3306/dwads?useUnicode=true&characterEncoding=utf-8",
						"table": [
							"ads_member_active_count"
						]
					}]
				}
			}
		}]
	}
}
   执行命令：
   python datax.py -p "-Ddo_date=2020-07-30"
/data/lagoudw/script/member_active/export_member_active_count.json
   
   export_member_active_count.sh

#!/bin/bash
JSON=/data/lagoudw/script/member_active

source /etc/profile

if [ -n "$1" ] ;then
    do_date=$1
else
    do_date=`date -d "-1 day" +%F`
fi

python $DATAX_HOME/bin/datax.py -p "-Ddo_date=$do_date" $JSON/export_member_active_count.json

